const path = require('path')
const {BrowserWindow, ipcMain} = require("electron");
const {enable} = require("@/common/winUtils/enable");
const config = require('@/common/winUtils/config')
let {ico, preload} = config.getAppConfig()
let domain = process.env.VUE_APP_WEB_DOMAIN
let win = null

const adWin = {
  createWin: () => {
    win = new BrowserWindow({
      transparent: true,
      backgroundColor: '#00000000',
      modal: true,
      frame: false,
      icon: ico,
      resizable: false,
      maximizable: false,
      minimizable: false,
      show: false,
      title: "电竞蜂网咖",
      webPreferences: {
        partition: String(+new Date()),
        plugins: true, //是否支持插件
        nodeIntegration: true,
        contextIsolation: false,
        webViewTag: true,
        webSecurity: false,
        enableRemoteModule: true
      }
    })
    if (process.env.ENV == 'development') {
      win.loadURL(`${process.env.VUE_APP_WEB_DOMAIN}/modal`, { extraHeaders: "pragma: no-cache\n" });
    } else {
      win.loadURL(`file://${path.join(__dirname, 'index.html')}#/modal`);
    }
    enable(win)
    win.on('closed', () => {
      win = null
    })
    ipcMain.on('close-modal-win', () => {
      win.close()
    })
    ipcMain.on('resize-modal-win', (event, data) => {
      win.setBounds({width: data.width, height: data.height})
      win.center()
      win.show()
    })
  },
  closeWin: () => {
    win && win.close()
  }
}
module.exports = adWin;
